import { DataApi, DataVO, StandardApi, StandardVO } from "@/utils/api";
import { appendDataToDailyExcel, HealthDataRecord } from '@/utils/excelGenerator';
import { exportHealthReportToPdf } from '@/utils/pdfExporter';
import {
    calculateFatigueIndex,
    calculateHealthIndex,
    calculateOverallIndex
} from '@/utils/score';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useLocalSearchParams, useRouter } from 'expo-router';
import React, { useEffect, useState } from 'react';
import {
    Alert,
    Image,
    Platform,
    SafeAreaView,
    ScrollView,
    StyleSheet,
    Text,
    TouchableOpacity,
    View
} from 'react-native';

const ExaminationResults: React.FC = () => {
    const router = useRouter();
    const params = useLocalSearchParams();
    const [isSavingLocal, setIsSavingLocal] = useState(false);
    const [isUploading, setIsUploading] = useState(false);
    const [isExportingPdf, setIsExportingPdf] = useState(false);
    const [standardData, setStandardData] = useState<StandardVO | null>(null);

    // 记录检测时间，在组件加载时生成
    const testTime = new Date();

    // 移除屏幕方向设置，保持横屏模式

    // 获取标准数据
    useEffect(() => {
        const fetchStandardData = async () => {
            try {
                // 获取最新的标准数据
                const response = await StandardApi.getStandardPage({ pageNo: 1, pageSize: 1 });
                if (response.code === 0 && response.data.list && response.data.list.length > 0) {
                    setStandardData(response.data.list[0]);
                }
            } catch (error) {
                console.error('获取标准数据失败:', error);
            }
        };

        fetchStandardData();
    }, []);

    // 从参数中解析数据，添加错误处理
    let healthData: any = {};
    let userInfo: any = {};

    try {
        if (params.healthData) {
            const healthDataStr = String(params.healthData);
            healthData = JSON.parse(healthDataStr);
            console.log('解析后的 healthData:', healthData);
        }
        if (params.userInfo) {
            const userInfoStr = String(params.userInfo);
            userInfo = JSON.parse(userInfoStr);
            console.log('解析后的 userInfo:', userInfo);
        }
    } catch (error) {
        console.error('解析参数失败:', error);
        console.error('healthData 参数:', params.healthData);
        console.error('userInfo 参数:', params.userInfo);
    }

    // 保存到本地
    const saveToLocal = async () => {
        setIsSavingLocal(true);
        try {
            // 从healthData中获取各项指标值
            const heartRate = healthData.heartRate;
            const bloodPressureLow = healthData.bloodPressureDiastolic;
            const bloodPressureHigh = healthData.bloodPressureSystolic;
            const spo2 = healthData.bloodOxygen;
            const stressIndex = healthData.stressIndex;
            const heartAttackIndex = healthData.heartAttackIndex;
            const reactionTime = healthData.reactionTime;
            const gripStrength = healthData.gripStrength;
            const flicker = healthData.flicker;
            const vitalCapacity = healthData.vitalCapacity;
            const alcohol = healthData.alcohol;

            // 从传递过来的数据中获取各项判定分，如果没有则使用默认值0
            const heartRateScore = healthData.heartRateScore || 0;
            const bloodPressureLowScore = healthData.bloodPressureLowScore || 0;
            const bloodPressureHighScore = healthData.bloodPressureHighScore || 0;
            const spo2Score = healthData.spo2Score || 0;
            const stressIndexScore = healthData.stressIndexScore || 0;
            const heartAttackRiskScore = healthData.heartAttackRiskScore || 0;
            const reactionTimeScore = healthData.reactionTimeScore || 0;
            const gripStrengthScore = healthData.gripStrengthScore || 0;
            const flickerScore = healthData.flickerScore || 0;
            const vitalCapacityScore = healthData.vitalCapacityScore || 0;
            const alcoholScore = healthData.alcoholScore || 0;

            // 优先使用传递过来的已计算好的指数值，如果没有则自己计算
            const healthIndex = typeof healthData.healthIndex === 'number' ? healthData.healthIndex : calculateHealthIndex(heartRateScore, (bloodPressureLowScore + bloodPressureHighScore) / 2, spo2Score, stressIndexScore, heartAttackRiskScore);
            const emotionIndex = typeof healthData.emotionIndex === 'number' ? healthData.emotionIndex : stressIndexScore;
            const fatigueIndex = typeof healthData.fatigueIndex === 'number' ? healthData.fatigueIndex : calculateFatigueIndex(flickerScore, alcoholScore, reactionTimeScore, gripStrengthScore, vitalCapacityScore);
            const overallIndex = typeof healthData.overallIndex === 'number' ? healthData.overallIndex : calculateOverallIndex(healthIndex, emotionIndex, fatigueIndex);

            const timestamp = new Date().toISOString();
            const saveData = {
                timestamp,
                userInfo,
                healthData,
                date: new Date().toLocaleDateString('zh-CN')
            };

            // 1. 保存到AsyncStorage（保留原有功能）
            const existingData = await AsyncStorage.getItem('localTestResults');
            const resultsList = existingData ? JSON.parse(existingData) : [];

            // 添加新数据
            resultsList.unshift(saveData);

            // 只保留最近50条记录
            if (resultsList.length > 50) {
                resultsList.splice(50);
            }

            // 保存到本地
            await AsyncStorage.setItem('localTestResults', JSON.stringify(resultsList));

            // 2. 添加到当天的Excel文件
            let excelFilePath = '';
            try {
                const excelRecord: HealthDataRecord = {
                    timestamp: new Date().toLocaleString('zh-CN', {
                        year: 'numeric',
                        month: '2-digit',
                        day: '2-digit',
                        hour: '2-digit',
                        minute: '2-digit',
                        second: '2-digit',
                    }),
                    userInfo: {
                        id: userInfo.id || 'unknown',
                        name: userInfo.nickname || '未知用户',
                    },
                    healthData: {
                        heartRate: heartRate !== undefined ? heartRate : -1, // -1表示未测试
                        bloodPressureSystolic: bloodPressureHigh !== undefined ? bloodPressureHigh : -1,
                        bloodPressureDiastolic: bloodPressureLow !== undefined ? bloodPressureLow : -1,
                        bloodOxygen: spo2 !== undefined ? spo2 : -1,
                        stressIndex: stressIndex !== undefined ? stressIndex : -1,
                        heartAttackIndex: heartAttackIndex !== undefined ? heartAttackIndex : -1,
                        reactionTime: reactionTime !== undefined ? reactionTime : -1,
                        gripStrength: gripStrength !== undefined ? gripStrength : -1,
                        flicker: flicker !== undefined ? flicker : -1,
                        vitalCapacity: vitalCapacity !== undefined ? vitalCapacity : -1,
                        alcohol: alcohol !== undefined ? alcohol : -1, // -1表示未测试，-2表示未检测
                        healthIndex: healthIndex !== undefined ? healthIndex : -1,
                        emotionIndex: emotionIndex !== undefined ? emotionIndex : -1,
                        fatigueIndex: fatigueIndex !== undefined ? fatigueIndex : -1,
                        overallIndex: overallIndex !== undefined ? overallIndex : -1,
                        level: healthData.level,
                    },
                    date: new Date().toLocaleDateString('zh-CN'),
                };

                excelFilePath = await appendDataToDailyExcel(excelRecord);
                console.log('数据已成功添加到Excel文件:', excelFilePath);
            } catch (excelError) {
                console.error('保存到Excel失败:', excelError);
                // Excel保存失败不影响整体保存流程，只记录错误
            }

            // 显示保存成功信息，并提供分享选项
            Alert.alert(
                '保存成功',
                '测试结果已保存到本地\n\n' +
                '注意：Excel文件保存在应用私有目录\n' +
                '您可以使用"分享文件"功能导出到其他位置',
                [
                    { text: '确定', style: 'default' },
                    ...(excelFilePath ? [{
                        text: '分享Excel文件',
                        onPress: async () => {
                            try {
                                const { shareExcelFile } = await import('@/utils/excelGenerator');
                                await shareExcelFile();
                            } catch (error) {
                                console.error('分享文件失败:', error);
                                Alert.alert('错误', '分享文件失败，请重试');
                            }
                        }
                    }] : [])
                ]
            );
        } catch (error) {
            console.error('保存到本地失败:', error);
            Alert.alert('错误', `保存到本地失败: ${error instanceof Error ? error.message : '未知错误'}`);
        } finally {
            setIsSavingLocal(false);
        }
    };

    // 上传到服务器
    const uploadToServer = async () => {
        setIsUploading(true);
        console.log('上传数据:', healthData)
        try {
            // 从healthData中获取各项指标值
            const heartRate = healthData.heartRate;
            const bloodPressureLow = healthData.bloodPressureDiastolic;
            const bloodPressureHigh = healthData.bloodPressureSystolic;
            const spo2 = healthData.bloodOxygen;
            const stressIndex = healthData.stressIndex;
            const heartAttackIndex = healthData.heartAttackIndex;
            const reactionTime = healthData.reactionTime;
            const gripStrength = healthData.gripStrength;
            const flicker = healthData.flicker;
            const vitalCapacity = healthData.vitalCapacity;
            const alcohol = healthData.alcohol;

            // 从传递过来的数据中获取各项判定分，如果没有则使用默认值0
            const heartRateScore = healthData.heartRateScore || 0;
            const bloodPressureLowScore = healthData.bloodPressureLowScore || 0;
            const bloodPressureHighScore = healthData.bloodPressureHighScore || 0;
            const spo2Score = healthData.spo2Score || 0;
            const stressIndexScore = healthData.stressIndexScore || 0;
            const heartAttackRiskScore = healthData.heartAttackRiskScore || 0;
            const reactionTimeScore = healthData.reactionTimeScore || 0;
            const gripStrengthScore = healthData.gripStrengthScore || 0;
            const flickerScore = healthData.flickerScore || 0;
            const vitalCapacityScore = healthData.vitalCapacityScore || 0;
            const alcoholScore = healthData.alcoholScore || 0;

            // 优先使用传递过来的已计算好的指数值，如果没有则自己计算
            const healthIndex = typeof healthData.healthIndex === 'number' ? healthData.healthIndex : calculateHealthIndex(heartRateScore, (bloodPressureLowScore + bloodPressureHighScore) / 2, spo2Score, stressIndexScore, heartAttackRiskScore);
            const emotionIndex = typeof healthData.emotionIndex === 'number' ? healthData.emotionIndex : stressIndexScore;
            const fatigueIndex = typeof healthData.fatigueIndex === 'number' ? healthData.fatigueIndex : calculateFatigueIndex(flickerScore, alcoholScore, reactionTimeScore, gripStrengthScore, vitalCapacityScore);
            const overallIndex = typeof healthData.overallIndex === 'number' ? healthData.overallIndex : calculateOverallIndex(healthIndex, emotionIndex, fatigueIndex);

            // 创建符合API接口要求的数据对象，进行字段映射
            const apiData: DataVO = {
                id: 0, // 新增数据时通常不需要提供id，由后端生成
                recordTime: testTime, // 使用组件加载时记录的检测时间
                userId: userInfo.id || '',
                heartRate: heartRate !== undefined ? heartRate : -1, // -1表示未测试
                oxygenSaturation: spo2 !== undefined ? spo2 : -1,
                systolicPressure: bloodPressureHigh !== undefined ? bloodPressureHigh : -1,
                diastolicPressure: bloodPressureLow !== undefined ? bloodPressureLow : -1,
                vitalCapacity: vitalCapacity !== undefined ? vitalCapacity : -1,
                gripStrength: gripStrength !== undefined ? gripStrength : -1,
                breathAlcohol: alcohol !== undefined ? (alcohol === -1 ? -2 : alcohol) : -1, // -1表示未测试，-2表示未检测
                heartAttackIndex: heartAttackIndex !== undefined ? heartAttackIndex : -1,
                stressIndex: stressIndex !== undefined ? stressIndex : -1,
                reactionTime: reactionTime !== undefined ? reactionTime : -1,
                health: healthIndex !== undefined ? healthIndex : -1, // 映射 healthIndex -> health
                mood: emotionIndex !== undefined ? emotionIndex : -1, // 映射 emotionIndex -> mood
                fatigue: fatigueIndex !== undefined ? fatigueIndex : -1, // 映射 fatigueIndex -> fatigue
                comprehensive: overallIndex !== undefined ? overallIndex : -1, // 映射 overallIndex -> comprehensive
                level: healthData.level || 3, // 默认为一般
            };

            const response = await DataApi.createData(apiData);

            if (response.code === 0) {
                Alert.alert('成功', '测试结果已上传到服务器');
            } else {
                throw new Error(response.msg || '上传失败');
            }
        } catch (error) {
            console.error('上传到服务器失败:', error);
            Alert.alert('错误', `上传失败: ${error instanceof Error ? error.message : '未知错误'}`);
        } finally {
            setIsUploading(false);
        }
    };

    // 从healthData中获取各项指标值
    const heartRate = healthData.heartRate;
    const bloodPressureLow = healthData.bloodPressureDiastolic;
    const bloodPressureHigh = healthData.bloodPressureSystolic;
    const spo2 = healthData.bloodOxygen;
    const stressIndex = healthData.stressIndex;
    const heartAttackIndex = healthData.heartAttackIndex;
    const reactionTime = healthData.reactionTime;
    const gripStrength = healthData.gripStrength;
    const flicker = healthData.flicker;
    const vitalCapacity = healthData.vitalCapacity;
    const alcohol = healthData.alcohol;

    // 从传递过来的数据中获取各项判定分，如果没有则使用默认值0
    const heartRateScore = healthData.heartRateScore || 0;
    const bloodPressureLowScore = healthData.bloodPressureLowScore || 0;
    const bloodPressureHighScore = healthData.bloodPressureHighScore || 0;
    const spo2Score = healthData.spo2Score || 0;
    const stressIndexScore = healthData.stressIndexScore || 0;
    const heartAttackRiskScore = healthData.heartAttackRiskScore || 0;
    const reactionTimeScore = healthData.reactionTimeScore || 0;
    const gripStrengthScore = healthData.gripStrengthScore || 0;
    const flickerScore = healthData.flickerScore || 0;
    const vitalCapacityScore = healthData.vitalCapacityScore || 0;
    const alcoholScore = healthData.alcoholScore || 0;

    // 优先使用传递过来的已计算好的指数值，如果没有则自己计算
    const healthIndex = typeof healthData.healthIndex === 'number' ? healthData.healthIndex : calculateHealthIndex(heartRateScore, (bloodPressureLowScore + bloodPressureHighScore) / 2, spo2Score, stressIndexScore, heartAttackRiskScore);
    const emotionIndex = typeof healthData.emotionIndex === 'number' ? healthData.emotionIndex : stressIndexScore;
    const fatigueIndex = typeof healthData.fatigueIndex === 'number' ? healthData.fatigueIndex : calculateFatigueIndex(flickerScore, alcoholScore, reactionTimeScore, gripStrengthScore, vitalCapacityScore);
    const overallIndex = typeof healthData.overallIndex === 'number' ? healthData.overallIndex : calculateOverallIndex(healthIndex, emotionIndex, fatigueIndex);

    // 确保所有值都是有效数字
    const safeHealthIndex = isNaN(healthIndex) || !isFinite(healthIndex) ? 0 : healthIndex;
    const safeEmotionIndex = isNaN(emotionIndex) || !isFinite(emotionIndex) ? 0 : emotionIndex;
    const safeFatigueIndex = isNaN(fatigueIndex) || !isFinite(fatigueIndex) ? 0 : fatigueIndex;
    const safeOverallIndex = isNaN(overallIndex) || !isFinite(overallIndex) ? 0 : overallIndex;

    // 获取评级
    const getRating = (index: number): string => {
        if (index >= 85) return '优';
        if (index >= 68 && index < 85) return '良';
        return '差';
    };

    // 获取健康指标状态描述
    const getHealthStatus = (metricType: string, value: number): string => {
        switch (metricType) {
            case 'heartRate':
                if (value < 60) return '偏低';
                if (value > 100) return '偏高';
                return '正常';
            case 'bloodPressureLow':
                if (value < 90) return '偏低';
                if (value > 140) return '偏高';
                return '正常';
            case 'bloodPressureHigh':
                if (value < 60) return '偏低';
                if (value > 90) return '偏高';
                return '正常';
            case 'spo2':
                if (value < 95) return '偏低';
                return '正常';
            case 'reactionTime':
                if (value > 600) return '偏高';
                return '正常';
            case 'gripStrength':
                if (value < 20) return '偏低';
                if (value > 50) return '偏高';
                return '正常';
            case 'vitalCapacity':
                if (value < 2500) return '偏低';
                return '正常';
            default:
                return '正常';
        }
    };

    // 根据健康状态获取样式
    const getHealthStatusStyle = (metricType: string, value: number) => {
        const status = getHealthStatus(metricType, value);
        if (status === '正常') return styles.normal;
        if (status === '偏高') return styles.high;
        if (status === '偏低') return styles.low;
        return styles.normal;
    };

    // 获取右上角评级样式
    const getTopRightRatingStyle = (index: number) => {
        if (index >= 85) return styles.scoreExcellent;
        if (index >= 68 && index < 85) return styles.scoreGood;
        return styles.scorePoor;
    };

    // 导出为PDF
    const exportToPdf = async () => {
        console.log('导出PDF按钮被点击');
        try {
            // 准备传递给PDF导出器的数据
            const pdfHealthData = {
                heartRate,
                bloodPressureDiastolic: bloodPressureLow,
                bloodPressureSystolic: bloodPressureHigh,
                bloodOxygen: spo2,
                stressIndex,
                heartAttackIndex,
                reactionTime,
                gripStrength,
                flicker,
                vitalCapacity,
                alcohol,
                healthIndex: safeHealthIndex,
                emotionIndex: safeEmotionIndex,
                fatigueIndex: safeFatigueIndex,
                overallIndex: safeOverallIndex
            };

            // 准备标准数据
            const pdfStandardData = standardData ? {
                heartRate: standardData.heartRate,
                oxygenSaturation: standardData.oxygenSaturation,
                systolicPressure: standardData.systolicPressure,
                diastolicPressure: standardData.diastolicPressure,
                vitalCapacity: standardData.vitalCapacity,
                gripStrength: standardData.gripStrength,
                reactionTime: standardData.reactionTime,
                breathAlcohol: standardData.breathAlcohol,
                stress: standardData.stress,
                richSore1: standardData.richSore1,
            } : undefined;

            console.log('准备调用exportHealthReportToPdf函数');
            await exportHealthReportToPdf(pdfHealthData, userInfo, testTime.toLocaleString(), setIsExportingPdf, pdfStandardData);
            console.log('exportHealthReportToPdf函数调用完成');
        } catch (error) {
            console.error('导出PDF过程中发生错误:', error);
            Alert.alert('错误', `导出PDF失败: ${error instanceof Error ? error.message : '未知错误'}`);
        }
    };

    return (
        <SafeAreaView style={styles.container}>
            <ScrollView style={styles.scrollView} showsVerticalScrollIndicator={false}>
                {/* 头部信息和综合评分 - 现代化设计 */}
                <View style={styles.headerCard}>
                    <View style={styles.headerTop}>
                        <View style={styles.titleSection}>
                            <Text style={styles.title}>检测结果</Text>
                        </View>
                    </View>

                    <View style={styles.headerContent}>
                        <View style={styles.userInfoCard}>
                            <View style={styles.userInfoHeader}>
                                <View style={styles.userDetails}>
                                    <Text style={styles.userName}>{userInfo.nickname || '未知用户'}</Text>
                                    <View style={styles.userInfoRow}>
                                        <View style={styles.userIdContainer}>
                                            <Text style={styles.userIdLabel}>ID</Text>
                                            <Text style={styles.userIdSeparator}>•</Text>
                                            <Text style={styles.userId}>{userInfo.id || '-'}</Text>
                                        </View>
                                        {userInfo.mobile && (
                                            <View style={[styles.userPhoneContainer, styles.userIdContainer]}>
                                                <Text style={styles.userIdLabel}>电话</Text>
                                                <Text style={styles.userIdSeparator}>•</Text>
                                                <Text style={styles.userId}>{userInfo.mobile}</Text>
                                            </View>
                                        )}
                                        {userInfo.sex && (
                                            <View style={[styles.userMetaContainer, styles.userIdContainer]}>
                                                <Text style={styles.userIdLabel}>性别</Text>
                                                <Text style={styles.userIdSeparator}>•</Text>
                                                <Text style={styles.userId}>
                                                    {userInfo.sex === 1 || userInfo.sex === 'male' ? '男' : '女'}
                                                    {userInfo.age ? ` ${userInfo.age}岁` : ''}
                                                </Text>
                                            </View>
                                        )}
                                    </View>
                                    <View style={styles.userInfoRow}>
                                        <View style={styles.userIdContainer}>
                                            <Text style={styles.userIdLabel}>检测时间</Text>
                                            <Text style={styles.userIdSeparator}>•</Text>
                                            <Text style={styles.userId}>{testTime.toLocaleString()}</Text>
                                        </View>
                                    </View>
                                </View>
                                <View style={styles.avatarContainer}>
                                    {userInfo.avatar ? (
                                        <Image source={{ uri: userInfo.avatar }} style={styles.avatarImage} />
                                    ) : (
                                        <View style={styles.avatarPlaceholder}>
                                            <Text
                                                style={styles.avatarText}>{(userInfo.nickname || '未知用户').charAt(0)}</Text>
                                        </View>
                                    )}
                                </View>
                            </View>
                        </View>

                        <View style={styles.scoreCard}>
                            <View style={styles.scoreHeader}>
                                <Text style={styles.scoreTitle}>今日检测结果</Text>
                            </View>
                            <View style={styles.scoreContent}>
                                <View style={styles.scoreCircleContainer}>
                                    <View style={[styles.scoreCircle, getTopRightRatingStyle(safeOverallIndex)]}>
                                        <Text style={styles.scoreValue}>{getRating(safeOverallIndex)}</Text>
                                    </View>
                                </View>
                                <View style={styles.scoreDetails}>
                                    <Text style={styles.scoreIndexLabel}>综合指数</Text>
                                    <View style={styles.scoreIndexContainer}>
                                        <Text style={styles.scoreIndexValue}>{safeOverallIndex}</Text>
                                        <Text style={styles.scoreIndexUnit}>分</Text>
                                    </View>
                                </View>
                            </View>
                        </View>
                    </View>
                </View>

                <View style={styles.sectionCard}>
                    <View style={styles.sectionHeaderTop}>
                        <View style={styles.sectionTitleSection}>
                            <Text style={styles.sectionTitle}>健康指标详情</Text>
                        </View>
                    </View>
                    <View style={styles.sectionContent}>
                        <View style={styles.statusNetwork}>
                            {/* 心率卡片 */}
                            <View style={[styles.gridItem, styles.heartRateCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>心率</Text>
                                    <View style={[styles.scoreBadge, heartRate !== undefined && heartRate !== 0 ? getHealthStatusStyle('heartRate', heartRate) : styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{heartRate !== undefined && heartRate !== 0 ? getHealthStatus('heartRate', heartRate) : '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={heartRate !== undefined && heartRate !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {heartRate !== undefined && heartRate !== 0 ?
                                        <>{heartRate}{standardData?.heartRate ? <Text style={styles.baselineValue}>({standardData.heartRate})</Text> : ''}<Text style={styles.itemUnit}>bpm</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 血氧卡片 */}
                            <View style={[styles.gridItem, styles.spo2Card]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>血氧</Text>
                                    <View style={[styles.scoreBadge, spo2 !== undefined && spo2 !== 0 ? getHealthStatusStyle('spo2', spo2) : styles.notTested]}>
                                        <Text style={styles.scoreBadgeText}>{spo2 !== undefined && spo2 !== 0 ? getHealthStatus('spo2', spo2) : '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={spo2 !== undefined && spo2 !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {spo2 !== undefined && spo2 !== 0 ?
                                        <>{spo2}{standardData?.oxygenSaturation ? <Text style={styles.baselineValue}>({standardData.oxygenSaturation})</Text> : ''}<Text style={styles.itemUnit}>%</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 压力指数卡片 */}
                            <View style={[styles.gridItem, styles.stressIndexCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>压力指数</Text>
                                    <View style={[styles.scoreBadge, stressIndex !== undefined && stressIndex !== 0 ?
                                        (stressIndex <= 2.5 ? styles.excellent : stressIndex < 3 ? styles.good : stressIndex < 4 ? styles.normal : styles.poor) :
                                        styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{stressIndex !== undefined && stressIndex !== 0 ?
                                            (stressIndex <= 2.5 ? '低' : stressIndex < 3 ? '正常' : stressIndex < 4 ? '偏高' : '高') :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={stressIndex !== undefined && stressIndex !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {stressIndex !== undefined && stressIndex !== 0 ?
                                        <>{stressIndex}{standardData?.stress ? <Text style={styles.baselineValue}>({standardData.stress})</Text> : ''}</> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 心康指数卡片 */}
                            <View style={[styles.gridItem, styles.heartAttackCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>心康指数</Text>
                                    <View style={[styles.scoreBadge, heartAttackIndex !== undefined && heartAttackIndex !== 0 ?
                                        (heartAttackRiskScore === 100 ? styles.excellent : styles.poor) :
                                        styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{heartAttackIndex !== undefined && heartAttackIndex !== 0 ?
                                            (heartAttackRiskScore === 100 ? '低风险' : '高风险') :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={heartAttackIndex !== undefined && heartAttackIndex !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {heartAttackIndex !== undefined && heartAttackIndex !== 0 ?
                                        <>{heartAttackIndex}{standardData?.richSore1 ? <Text style={styles.baselineValue}>({standardData.richSore1})</Text> : ''}</> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 视觉疲劳检测卡片 */}
                            <View style={[styles.gridItem, styles.flickerCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>视觉疲劳</Text>
                                    <View style={[styles.scoreBadge, flicker !== undefined ?
                                        (flicker === 1 ? styles.excellent : styles.poor) :
                                        styles.notTested]}>
                                        <Text style={styles.scoreBadgeText}>{flicker !== undefined ?
                                            (flicker === 1 ? '正常' : '疲劳') :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={flicker !== undefined ? styles.itemValue : styles.notTestedText}>
                                    {flicker !== undefined ?
                                        (flicker === 1 ? '通过' : '未通过') :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 血压卡片 */}
                            <View style={[styles.gridItem, styles.bloodPressureCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>血压</Text>
                                    <View style={[styles.scoreBadge,
                                        (bloodPressureHigh !== undefined && bloodPressureLow !== undefined && bloodPressureHigh !== 0 && bloodPressureLow !== 0) ?
                                            (getHealthStatusStyle('bloodPressureLow', bloodPressureLow) === styles.normal && getHealthStatusStyle('bloodPressureHigh', bloodPressureHigh) === styles.normal ?
                                                styles.excellent :
                                                (getHealthStatusStyle('bloodPressureLow', bloodPressureLow) === styles.low || getHealthStatusStyle('bloodPressureHigh', bloodPressureHigh) === styles.low ||
                                                    getHealthStatusStyle('bloodPressureLow', bloodPressureLow) === styles.high || getHealthStatusStyle('bloodPressureHigh', bloodPressureHigh) === styles.high) ?
                                                    styles.poor : styles.normal) :
                                            styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{(bloodPressureHigh !== undefined && bloodPressureLow !== undefined && bloodPressureHigh !== 0 && bloodPressureLow !== 0) ?
                                            (getHealthStatus('bloodPressureLow', bloodPressureLow) === '正常' && getHealthStatus('bloodPressureHigh', bloodPressureHigh) === '正常' ?
                                                '正常' :
                                                (getHealthStatus('bloodPressureLow', bloodPressureLow) === '偏低' || getHealthStatus('bloodPressureHigh', bloodPressureHigh) === '偏低' ||
                                                    getHealthStatus('bloodPressureLow', bloodPressureLow) === '偏高' || getHealthStatus('bloodPressureHigh', bloodPressureHigh) === '偏高') ?
                                                    '异常' : '一般') :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={(bloodPressureHigh !== undefined && bloodPressureLow !== undefined && bloodPressureHigh !== 0 && bloodPressureLow !== 0) ? styles.itemValue : styles.notTestedText}>
                                    {(bloodPressureHigh !== undefined && bloodPressureLow !== undefined && bloodPressureHigh !== 0 && bloodPressureLow !== 0) ?
                                        <>{bloodPressureHigh}{standardData?.systolicPressure ? <Text style={styles.baselineValue}>({standardData.systolicPressure})</Text> : ''}/{bloodPressureLow}{standardData?.diastolicPressure ? <Text style={styles.baselineValue}>({standardData.diastolicPressure})</Text> : ''}<Text style={styles.itemUnit}>mmHg</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 反应时卡片 */}
                            <View style={[styles.gridItem, styles.reactionTimeCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>反应时</Text>
                                    <View style={[styles.scoreBadge, reactionTime !== undefined && reactionTime !== 0 ?
                                        getHealthStatusStyle('reactionTime', reactionTime) :
                                        styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{reactionTime !== undefined && reactionTime !== 0 ?
                                            getHealthStatus('reactionTime', reactionTime) :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={reactionTime !== undefined && reactionTime !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {reactionTime !== undefined && reactionTime !== 0 ?
                                        <>{reactionTime}{standardData?.reactionTime ? <Text style={styles.baselineValue}>({standardData.reactionTime})</Text> : ''}<Text style={styles.itemUnit}>ms</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 握力卡片 */}
                            <View style={[styles.gridItem, styles.gripStrengthCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>握力</Text>
                                    <View style={[styles.scoreBadge, gripStrength !== undefined && gripStrength !== 0 ?
                                        getHealthStatusStyle('gripStrength', gripStrength) :
                                        styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{gripStrength !== undefined && gripStrength !== 0 ?
                                            getHealthStatus('gripStrength', gripStrength) :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={gripStrength !== undefined && gripStrength !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {gripStrength !== undefined && gripStrength !== 0 ?
                                        <>{gripStrength}{standardData?.gripStrength ? <Text style={styles.baselineValue}>({standardData.gripStrength})</Text> : ''}<Text style={styles.itemUnit}>kg</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 肺活量卡片 */}
                            <View style={[styles.gridItem, styles.vitalCapacityCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>肺活量</Text>
                                    <View style={[styles.scoreBadge, vitalCapacity !== undefined && vitalCapacity !== 0 ?
                                        getHealthStatusStyle('vitalCapacity', vitalCapacity) :
                                        styles.notTested]}>
                                        <Text
                                            style={styles.scoreBadgeText}>{vitalCapacity !== undefined && vitalCapacity !== 0 ?
                                            getHealthStatus('vitalCapacity', vitalCapacity) :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={vitalCapacity !== undefined && vitalCapacity !== 0 ? styles.itemValue : styles.notTestedText}>
                                    {vitalCapacity !== undefined && vitalCapacity !== 0 ?
                                        <>{vitalCapacity}{standardData?.vitalCapacity ? <Text style={styles.baselineValue}>({standardData.vitalCapacity})</Text> : ''}<Text style={styles.itemUnit}>ml</Text></> :
                                        '未测试'}
                                </Text>
                            </View>

                            {/* 酒精检测卡片 */}
                            <View style={[styles.gridItem, styles.alcoholCard]}>
                                <View style={styles.itemHeader}>
                                    <Text style={styles.itemTitle}>酒精含量</Text>
                                    <View style={[styles.scoreBadge, alcohol !== undefined ?
                                        (alcohol === -1 ? styles.poor : (alcohol <= 20 ? styles.excellent : styles.poor)) :
                                        styles.notTested]}>
                                        <Text style={styles.scoreBadgeText}>{alcohol !== undefined ?
                                            (alcohol === -1 ? '未检测' : (alcohol <= 20 ? '正常' : '超标')) :
                                            '未测试'}</Text>
                                    </View>
                                </View>
                                <Text style={alcohol !== undefined ? styles.itemValue : styles.notTestedText}>
                                    {alcohol !== undefined ?
                                        (alcohol === -1 ? '未检测' :
                                                <>{alcohol}{standardData?.breathAlcohol ? <Text style={styles.baselineValue}>({standardData.breathAlcohol})</Text> : ''}<Text style={styles.itemUnit}>mg/L</Text></>
                                        ) :
                                        '未测试'}
                                </Text>
                            </View>
                        </View>
                    </View>
                </View>

                {/* 综合评估 - 整合标题和内容 */
                }
                <View style={styles.sectionCard}>
                    <View style={styles.sectionHeaderTop}>
                        <View style={styles.sectionTitleSection}>
                            <Text style={styles.sectionTitle}>综合评估</Text>
                        </View>
                    </View>
                    <View style={styles.sectionContent}>
                        <View style={styles.evaluationGrid}>
                            <View style={[styles.evaluationCard, styles.healthIndexCard]}>
                                <View style={styles.evaluationRow}>
                                    <View style={[styles.evaluationIconContainer, {backgroundColor: 'rgba(76, 175, 80, 0.15)'}]}>
                                        <Text style={[styles.evaluationIcon, {color: '#4CAF50'}]}>♥</Text>
                                    </View>
                                    <View style={styles.evaluationTextContainer}>
                                        <Text style={styles.evaluationCardTitle}>健康指数</Text>
                                        <Text style={healthIndex !== undefined ? styles.evaluationCardValue : styles.notTestedText}>
                                            {healthIndex !== undefined ? safeHealthIndex : '未测试'}
                                        </Text>
                                    </View>
                                </View>
                            </View>

                            <View style={[styles.evaluationCard, styles.emotionIndexCard]}>
                                <View style={styles.evaluationRow}>
                                    <View style={[styles.evaluationIconContainer, {backgroundColor: 'rgba(156, 39, 176, 0.15)'}]}>
                                        <Text style={[styles.evaluationIcon, {color: '#9C27B0'}]}>☺</Text>
                                    </View>
                                    <View style={styles.evaluationTextContainer}>
                                        <Text style={styles.evaluationCardTitle}>情绪指数</Text>
                                        <Text style={emotionIndex !== undefined ? styles.evaluationCardValue : styles.notTestedText}>
                                            {emotionIndex !== undefined ? safeEmotionIndex : '未测试'}
                                        </Text>
                                    </View>
                                </View>
                            </View>

                            <View style={[styles.evaluationCard, styles.fatigueIndexCard]}>
                                <View style={styles.evaluationRow}>
                                    <View style={[styles.evaluationIconContainer, {backgroundColor: 'rgba(255, 152, 0, 0.15)'}]}>
                                        <Text style={[styles.evaluationIcon, {color: '#FF9800'}]}>⚡</Text>
                                    </View>
                                    <View style={styles.evaluationTextContainer}>
                                        <Text style={styles.evaluationCardTitle}>疲劳指数</Text>
                                        <Text style={fatigueIndex !== undefined ? styles.evaluationCardValue : styles.notTestedText}>
                                            {fatigueIndex !== undefined ? safeFatigueIndex : '未测试'}
                                        </Text>
                                    </View>
                                </View>
                            </View>
                        </View>
                    </View>
                </View>

                {/* 隐私声明和免责声明 */}
                <View style={styles.sectionCard}>
                    <View style={styles.sectionHeaderTop}>
                        <View style={styles.sectionTitleSection}>
                            <Text style={styles.sectionTitle}>隐私与免责声明</Text>
                        </View>
                    </View>
                    <View style={styles.sectionContent}>
                        <View style={styles.disclaimerContainer}>
                            <View style={styles.disclaimerSection}>
                                <Text style={styles.disclaimerTitle}>隐私声明</Text>
                                <Text style={styles.disclaimerText}>
                                    我们重视您的隐私安全。您的健康数据将被加密存储，仅用于健康评估和改善建议。未经您的明确同意，我们不会向任何第三方分享您的个人健康信息。
                                </Text>
                            </View>
                            
                            <View style={styles.disclaimerSection}>
                                <Text style={styles.disclaimerTitle}>免责声明</Text>
                                <Text style={styles.disclaimerText}>
                                    本应用提供的健康评估结果仅供参考，不能替代专业医疗诊断。如有健康问题，请咨询专业医疗机构。本应用不对因使用本评估结果而产生的任何后果承担责任。
                                </Text>
                            </View>
                        </View>
                    </View>
                </View>
            </ScrollView>

            {/* 底部操作按钮 - 固定在页面底部 */}
            <View style={styles.actionContainer}>
                <TouchableOpacity
                    style={[styles.actionButton, styles.localButton]}
                    onPress={saveToLocal}
                    disabled={isSavingLocal}
                >
                    <Text style={styles.buttonText}>
                        {isSavingLocal ? '保存中...' : '保存到本地'}
                    </Text>
                </TouchableOpacity>

                <TouchableOpacity
                    style={[styles.actionButton, styles.uploadButton]}
                    onPress={uploadToServer}
                    disabled={isUploading}
                >
                    <Text style={[styles.buttonText, styles.uploadButtonText]}>
                        {isUploading ? '上传中...' : '上传系统'}
                    </Text>
                </TouchableOpacity>

                <TouchableOpacity
                    style={[styles.actionButton, styles.pdfButton]}
                    onPress={exportToPdf}
                    disabled={isExportingPdf}
                >
                    <Text style={[styles.buttonText, styles.pdfButtonText]}>
                        {isExportingPdf ? '导出中...' : '导出PDF'}
                    </Text>
                </TouchableOpacity>
            </View>
        </SafeAreaView>
    )
        ;
};

// 获取评级样式
const getRatingStyle = (index: number) => {
    if (index >= 85) return styles.excellent;
    if (index >= 68) return styles.good;
    return styles.poor;
};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        marginTop: 3,
        backgroundColor: '#f5f5f5',
    },
    scrollView: {
        flex: 1,
        paddingBottom: 60, // 为底部固定按钮留出空间
    },
    // 现代化设计的头部卡片
    headerCard: {
        backgroundColor: '#fff',
        margin: 4, // 减小外边距
        marginTop: 20, // 减小顶部边距
        borderRadius: 12,
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.1,
        shadowRadius: 4,
        elevation: 3,
        overflow: 'hidden',
    },
    headerTop: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        backgroundColor: '#4285F4',
        paddingHorizontal: 16,
        paddingVertical: 12,
    },
    titleSection: {
        flex: 1,
    },
    title: {
        fontSize: 18,
        fontWeight: 'bold',
        color: '#fff',
        marginBottom: 2,
    },
    subtitle: {
        fontSize: 12,
        color: 'rgba(255, 255, 255, 0.8)',
    },
    timeSection: {
        alignItems: 'flex-end',
    },
    timeLabel: {
        fontSize: 11,
        color: 'rgba(255, 255, 255, 0.7)',
        marginBottom: 2,
    },
    timeValue: {
        fontSize: 12,
        color: '#fff',
        fontWeight: '500',
    },
    headerContent: {
        flexDirection: 'row',
        padding: 12, // 横屏模式下减小内边距以节省空间
        backgroundColor: '#fff',
    },
    userInfoCard: {
        flex: 1.2, // 横屏模式下调整比例
        backgroundColor: '#fff',
        borderRadius: 12,
        padding: 12, // 减小内边距
        marginRight: 10, // 减小右边距
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.08,
        shadowRadius: 4,
        elevation: 3,
        borderLeftWidth: 4,
        borderLeftColor: '#4285F4',
    },
    userInfoHeader: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    avatarContainer: {
        marginLeft: 14,
    },
    avatarImage: {
        width: 80, // 横屏模式下减小头像尺寸
        height: 80,
        borderRadius: 8,
        borderWidth: 2,
        borderColor: '#f0f0f0',
    },
    avatarPlaceholder: {
        width: 60, // 横屏模式下减小尺寸
        height: 60,
        borderRadius: 30,
        backgroundColor: '#4285F4',
        justifyContent: 'center',
        alignItems: 'center',
        borderWidth: 2,
        borderColor: '#f0f0f0',
    },
    avatarText: {
        fontSize: 24, // 横屏模式下减小字体大小
        fontWeight: 'bold',
        color: '#fff',
    },
    userDetails: {
        flex: 1,
    },
    userNameContainer: {
        marginBottom: 8,
    },
    userName: {
        fontSize: 20,
        fontWeight: '700',
        color: '#1a1a1a',
        marginBottom: 8,
    },
    userIdContainer: {
        flexDirection: 'row',
        alignItems: 'center',
        backgroundColor: '#f5f5f5',
        alignSelf: 'flex-start',
        paddingHorizontal: 10,
        paddingVertical: 4,
        borderRadius: 12,
    },
    userInfoRow: {
        paddingTop: 2,
        flexDirection: 'row',
        alignItems: 'center',
        flexWrap: 'wrap',
        gap: 8,
    },
    userIdLabel: {
        fontSize: 14,
        color: '#666',
        fontWeight: '500',
    },
    userIdSeparator: {
        fontSize: 14,
        color: '#999',
        marginHorizontal: 6,
    },
    userId: {
        fontSize: 14,
        color: '#333',
        fontWeight: '500',
    },
    userPhoneContainer: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    userPhone: {
        fontSize: 14,
        color: '#333',
        fontWeight: '500',
    },
    testTimeContainer: {
        marginTop: 8,
        backgroundColor: '#e8f4fd',
        alignSelf: 'flex-start',
        paddingHorizontal: 10,
        paddingVertical: 6,
        borderRadius: 12,
        borderLeftWidth: 3,
        borderLeftColor: '#4285F4',
    },
    testTimeLabel: {
        fontSize: 12,
        color: '#4285F4',
        fontWeight: '600',
        marginBottom: 2,
    },
    testTimeValue: {
        fontSize: 14,
        color: '#333',
        fontWeight: '500',
    },
    userMetaContainer: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    userMeta: {
        fontSize: 14,
        color: '#333',
        fontWeight: '500',
    },
    scoreCard: {
        flex: 0.8, // 横屏模式下增加比例
        backgroundColor: '#fff',
        borderRadius: 12,
        padding: 12, // 减小内边距
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.08,
        shadowRadius: 4,
        elevation: 3,
        borderLeftWidth: 4,
        borderLeftColor: '#4285F4',
    },
    scoreHeader: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        marginBottom: 8, // 减小底部边距
    },
    scoreTitle: {
        fontSize: 14,
        fontWeight: '600',
        color: '#333',
    },
    scoreContent: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-around',
        marginTop: 6, // 减小顶部边距
    },
    scoreCircleContainer: {
        alignItems: 'center',
        flex: 1,
    },
    scoreDetails: {
        alignItems: 'center',
        flex: 1,
    },
    scoreIndexLabel: {
        fontSize: 12, // 减小字体大小
        color: '#666',
        marginBottom: 4, // 减小底部边距
        fontWeight: '500',
    },
    scoreIndexContainer: {
        flexDirection: 'row',
        alignItems: 'baseline',
    },
    scoreIndexValue: {
        fontSize: 24, // 减小字体大小以减小高度
        fontWeight: 'bold',
        color: '#333',
    },
    scoreIndexUnit: {
        fontSize: 14,
        color: '#666',
        marginLeft: 2,
    },
    scoreContainer: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    scoreDetails: {
        marginLeft: 12,
        flex: 1,
    },
    scoreDescription: {
        fontSize: 12,
        color: '#666',
        marginTop: 8,
        textAlign: 'center',
    },
    scoreCircle: {
        width: 60, // 减小圆圈大小以减小高度
        height: 60,
        borderRadius: 30,
        justifyContent: 'center',
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.15,
        shadowRadius: 4,
        elevation: 3,
    },
    scoreValue: {
        fontSize: 18, // 减小字体大小以适应更小的圆圈
        fontWeight: 'bold',
        color: '#fff',
    },
    scoreLabel: {
        fontSize: 12,
        fontWeight: '600',
        color: '#fff',
        paddingHorizontal: 10,
        paddingVertical: 2,
        borderRadius: 6,
    },
    // 整合标题和内容的卡片样式
    sectionCard: {
        backgroundColor: '#fff',
        margin: 4, // 减小外边距
        borderRadius: 12,
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.1,
        shadowRadius: 4,
        elevation: 3,
        overflow: 'hidden',
    },
    sectionContent: {
        padding: 6, // 统一为6px
        backgroundColor: '#fff',
    },
    sectionHeaderTop: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        backgroundColor: '#4285F4',
        paddingHorizontal: 16,
        paddingVertical: 12,
    },
    sectionTitleSection: {
        flex: 1,
    },
    sectionTitle: {
        fontSize: 18,
        fontWeight: 'bold',
        color: '#fff',
        marginBottom: 2,
    },
    statusNetwork: {
        flexDirection: 'row',
        flexWrap: 'wrap',
        justifyContent: 'space-between',
        marginHorizontal: -4,
    },
    // 网格项 - 横屏每行五个
    gridItem: {
        width: '19%', // 横屏显示，每行五个
        backgroundColor: '#fff',
        borderRadius: 10,
        padding: 8, // 减小内边距以适应更小的空间
        marginBottom: 6, // 统一为6px
        marginHorizontal: '0.5%',
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.06,
        shadowRadius: 3,
        elevation: 2,
        borderLeftWidth: 3,
        borderLeftColor: '#4285F4',
    },
    // 心率卡片 - 红色系
    heartRateCard: {
        borderLeftColor: '#F44336',
    },
    // 血压卡片 - 紫色系
    bloodPressureCard: {
        borderLeftColor: '#9C27B0',
    },
    // 血氧卡片 - 蓝色系
    spo2Card: {
        borderLeftColor: '#2196F3',
    },
    // 压力指数卡片 - 橙色系
    stressIndexCard: {
        borderLeftColor: '#FF9800',
    },
    // 心康风险卡片 - 深红色系
    heartAttackCard: {
        borderLeftColor: '#D32F2F',
    },
    // 反应时卡片 - 青色系
    reactionTimeCard: {
        borderLeftColor: '#00BCD4',
    },
    // 握力卡片 - 绿色系
    gripStrengthCard: {
        borderLeftColor: '#4CAF50',
    },
    // 临界闪光融合频率卡片 - 黄色系
    flickerCard: {
        borderLeftColor: '#FFC107',
    },
    // 肺活量卡片 - 靛蓝色系
    vitalCapacityCard: {
        borderLeftColor: '#3F51B5',
    },
    // 呼气酒精含量卡片 - 粉色系
    alcoholCard: {
        borderLeftColor: '#E91E63',
    },
    gridItemWide: {
        width: '19%', // 横屏，调整为与其他网格项一致
        backgroundColor: '#fff',
        borderRadius: 10,
        padding: 8, // 减小内边距以适应更小的空间
        marginBottom: 8,
        marginHorizontal: '0.5%',
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.06,
        shadowRadius: 3,
        elevation: 2,
        borderLeftWidth: 3,
        borderLeftColor: '#4285F4',
    },
    // 双指标容器
    doubleMetricContainer: {
        flexDirection: 'row',
        justifyContent: 'space-around',
        width: '100%',
        alignItems: 'center',
        marginTop: 5,
    },
    // 单个指标项
    metricItem: {
        alignItems: 'center',
        flex: 1,
        paddingVertical: 5,
    },
    // 指标标签
    metricLabel: {
        fontSize: 12,
        color: '#666',
        marginBottom: 3,
    },
    // 指标值
    metricValue: {
        fontSize: 18,
        color: '#1a1a1a',
        fontWeight: '700',
        marginBottom: 3,
    },
    // 指标单位
    metricUnit: {
        fontSize: 11,
        color: '#888',
    },
    // 状态标签
    statusBadge: {
        paddingHorizontal: 8,
        paddingVertical: 3,
        borderRadius: 12,
        minWidth: 24,
        height: 24,
        justifyContent: 'center',
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.1,
        shadowRadius: 1,
        elevation: 1,
        marginTop: 4,
    },
    // 状态文本
    statusText: {
        fontSize: 11,
        fontWeight: 'bold',
        color: '#fff',
    },
    itemHeader: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        width: '100%',
        marginBottom: 6, // 减小底部边距以节省空间
    },
    itemTitle: {
        fontSize: 12, // 减小字体大小以适应更小的空间
        color: '#555',
        fontWeight: '500',
    },
    itemValue: {
        fontSize: 18, // 减小字体大小以适应更小的空间
        color: '#1a1a1a',
        fontWeight: '700',
        marginBottom: 2,
    },
    itemUnit: {
        fontSize: 11, // 减小字体大小以适应更小的空间
        color: '#888',
        marginBottom: 4,
    },
    baselineValue: {
        fontSize: 13, // 减小字体大小以适应更小的空间
        color: '#888',
        fontWeight: 'normal',
    },
    itemScore: {
        fontSize: 9,
        color: '#666',
    },
    scoreBadge: {
        paddingHorizontal: 6, // 减小水平内边距
        paddingVertical: 2, // 减小垂直内边距
        borderRadius: 10,
        minWidth: 20, // 减小最小宽度
        height: 20, // 减小高度
        justifyContent: 'center',
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.1,
        shadowRadius: 1,
        elevation: 1,
    },
    scoreBadgeText: {
        fontSize: 9, // 减小字体大小以适应更小的空间
        fontWeight: 'bold',
        color: '#fff',
    },
    // 卡片式评估布局 - 横屏模式
    evaluationGrid: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        marginHorizontal: -4,
    },
    evaluationCard: {
        width: '31%', // 横屏模式下调整卡片宽度
        backgroundColor: '#fff',
        borderRadius: 10,
        padding: 8, // 进一步减小内边距
        marginHorizontal: '0.5%', // 减小外边距
        marginBottom: 6, // 统一为6px
        alignItems: 'center',
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.08,
        shadowRadius: 3,
        elevation: 2,
        borderLeftWidth: 3,
        borderLeftColor: '#4285F4',
        minHeight: 75, // 进一步减小最小高度
    },
    // 健康指数卡片 - 绿色系
    healthIndexCard: {
        borderLeftColor: '#4CAF50',
    },
    // 情绪指数卡片 - 紫色系
    emotionIndexCard: {
        borderLeftColor: '#9C27B0',
    },
    // 疲劳指数卡片 - 橙色系
    fatigueIndexCard: {
        borderLeftColor: '#FF9800',
    },
    // 综合指数卡片 - 蓝色系
    overallIndexCard: {
        borderLeftColor: '#2196F3',
    },
    evaluationRow: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
    },
    evaluationIconContainer: {
        width: 36, // 减小图标容器以减小高度
        height: 36,
        borderRadius: 18,
        justifyContent: 'center',
        alignItems: 'center',
        marginRight: 6, // 减小右边距
    },
    evaluationIcon: {
        fontSize: 22, // 减小图标大小以减小高度
        fontWeight: 'bold',
    },
    evaluationTextContainer: {
        flex: 1,
        alignItems: 'center',
    },
    evaluationCardTitle: {
        fontSize: 16, // 减小标题字体
        fontWeight: '600',
        color: '#333',
        marginBottom: 2, // 减小底部间距
        textAlign: 'center',
    },
    evaluationCardDescription: {
        fontSize: 11,
        color: '#666',
        textAlign: 'center',
        lineHeight: 14,
    },
    evaluationCardValue: {
        fontSize: 24, // 减小数值字体
        fontWeight: '700',
        color: '#1a1a1a',
        marginBottom: 2, // 减小底部间距
        textAlign: 'center',
    },
    evaluationCardRating: {
        paddingHorizontal: 8,
        paddingVertical: 2,
        borderRadius: 4,
    },
    evaluationCardRatingText: {
        fontSize: 10,
        fontWeight: 'bold',
        color: '#fff',
    },
    excellent: {
        backgroundColor: '#2E7D32', // 深绿色背景
        shadowColor: '#2E7D32',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    good: {
        backgroundColor: '#1565C0', // 深蓝色背景
        shadowColor: '#1565C0',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    // normal: {
    //     backgroundColor: '#F57C00', // 深橙色背景
    //     shadowColor: '#F57C00',
    //     shadowOffset: {
    //         width: 0,
    //         height: 1,
    //     },
    //     shadowOpacity: 0.3,
    //     shadowRadius: 2,
    //     elevation: 2,
    // },
    poor: {
        backgroundColor: '#C62828', // 深红色背景
        shadowColor: '#C62828',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    // 右上角综合评级专用样式
    topRightExcellent: {
        backgroundColor: '#4CAF50', // 绿色背景
        shadowColor: '#4CAF50',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    topRightGood: {
        backgroundColor: '#87CEEB', // 浅蓝色背景
        shadowColor: '#87CEEB',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    topRightPoor: {
        backgroundColor: '#FF5252', // 红色背景
        shadowColor: '#FF5252',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    // 分数圆圈样式
    scoreExcellent: {
        backgroundColor: '#4CAF50', // 绿色背景
        shadowColor: '#4CAF50',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    scoreGood: {
        backgroundColor: '#87CEEB', // 浅蓝色背景
        shadowColor: '#87CEEB',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    scorePoor: {
        backgroundColor: '#FF5252', // 红色背景
        shadowColor: '#FF5252',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.3,
        shadowRadius: 4,
        elevation: 3,
    },
    // 健康状态样式
    normal: {
        backgroundColor: '#2E7D32', // 绿色表示正常
        shadowColor: '#2E7D32',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    high: {
        backgroundColor: '#E65100', // 深橙色表示偏高
        shadowColor: '#E65100',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    low: {
        backgroundColor: '#0D47A1', // 深蓝色表示偏低
        shadowColor: '#0D47A1',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    // 未测试状态样式
    untested: {
        backgroundColor: '#9E9E9E', // 灰色表示未测试
        shadowColor: '#9E9E9E',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    notTested: {
        backgroundColor: '#9E9E9E', // 灰色表示未测试
        shadowColor: '#9E9E9E',
        shadowOffset: {
            width: 0,
            height: 1,
        },
        shadowOpacity: 0.3,
        shadowRadius: 2,
        elevation: 2,
    },
    actionContainer: {
        position: 'absolute',
        bottom: 0,
        left: 0,
        right: 0,
        backgroundColor: '#fff',
        padding: 10,
        flexDirection: 'row',
        justifyContent: 'space-around',
        borderTopWidth: 1,
        borderTopColor: '#eee',
        paddingBottom: Platform.OS === 'ios' ? 20 : 8, // 为iOS安全区域留出空间
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: -2,
        },
        shadowOpacity: 0.05,
        shadowRadius: 3,
        elevation: 3,
    },
    actionButton: {
        flex: 1,
        height: 40,
        borderRadius: 10,
        justifyContent: 'center',
        alignItems: 'center',
        marginHorizontal: 8,
        shadowColor: '#000',
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.1,
        shadowRadius: 3,
        elevation: 2,
    },
    localButton: {
        backgroundColor: '#e3f2fd',
        borderWidth: 1.5,
        borderColor: '#2196f3',
    },
    shareButton: {
        backgroundColor: '#4CAF50',
        borderWidth: 1.5,
        borderColor: '#4CAF50',
    },
    pdfButton: {
        backgroundColor: '#FF9800',
        borderWidth: 1.5,
        borderColor: '#FF9800',
    },
    uploadButton: {
        backgroundColor: '#2196f3',
        borderWidth: 1.5,
        borderColor: '#2196f3',
    },
    buttonText: {
        fontSize: 16,
        fontWeight: '600',
        color: '#2196f3',
    },
    uploadButtonText: {
        color: '#fff',
    },
    shareButtonText: {
        color: '#fff',
    },
    pdfButtonText: {
        color: '#fff',
    },
    errorText: {
        fontSize: 14,
        color: '#f44336',
        textAlign: 'center',
        marginTop: 8,
    },
    // 未测试文本样式
    notTestedText: {
        fontSize: 16,
        color: '#757575',
        fontWeight: '500',
        fontStyle: 'italic',
    },
    // 隐私声明和免责声明样式
    disclaimerContainer: {
        padding: 8,
        flexDirection: 'row',
        justifyContent: 'space-between',
    },
    disclaimerSection: {
        width: '48%', // 横屏下保持相同的两列布局
        backgroundColor: '#f9f9f9',
        borderRadius: 8,
        padding: 10, // 增加内边距与其他卡片边距一致
        borderLeftWidth: 3,
        borderLeftColor: '#4285F4',
    },
    disclaimerTitle: {
        fontSize: 15, // 横屏模式下增加字体大小
        fontWeight: '600',
        color: '#333',
        marginBottom: 6,
    },
    disclaimerText: {
        fontSize: 13, // 横屏模式下增加字体大小
        color: '#666',
        lineHeight: 17, // 调整行高
        textAlign: 'justify',
    },
});

export default ExaminationResults;